package com.example.dinghao.zyfypt_312dh.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.example.dinghao.zyfypt_312dh.adapter.VideoAdapter;
import com.example.dinghao.zyfypt_312dh.bean.VideoBean;
import com.example.dinghao.zyfypt_312dh.iface.VideoListener;
import com.example.dinghao.zyfypt_312dh.model.VideoModel;
import com.example.dinghao.zyfypt_312dh.R;

import java.util.List;



public class Fragment32 extends Fragment {
    private View view=null;
    private Context context;
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private VideoAdapter videoAdapter;
    private List<VideoBean> list=null;
    VideoListener videoListener=new VideoListener() {
        @Override
        public void onResponse(List<VideoBean> beanList) {
            list=beanList;
            videoAdapter.setList(list);
            videoAdapter.notifyDataSetChanged();
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(context,msg, Toast.LENGTH_SHORT).show();
        }
    };

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        context=getActivity();
       //动态加载Fragment1的布局文件
        view=inflater.inflate(R.layout.fragment32,container,false);
        //获取布局上的控件，注意通过view获取

        //注意Toast第一个参数上下文
        //Toast.makeText(context, "加载Fragment通讯录", Toast.LENGTH_SHORT).show();
        //返回动态生成的view
        initRecycleView();
        VideoModel videoModel=new VideoModel();
        videoModel.getResultList("video",2,"k17vmm42ui9al6clh0lo3de2t7",videoListener);
        return view;
    }

    private void initRecycleView() {
        recyclerView=(RecyclerView)view.findViewById(R.id.recycleview);
        layoutManager=new LinearLayoutManager(context);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);
        // list=getData();
        videoAdapter =new VideoAdapter(context);
        videoAdapter.setList(list);
        recyclerView.setAdapter(videoAdapter);
    }
}
